home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Main.bin / GridBagLayout.java < prev    next >
Text File  |  1998-09-22  |  42KB  |  1,258 lines

  1. /*
  2.  * @(#)GridBagLayout.java    1.24 98/07/01
  3.  *
  4.  * Copyright 1995-1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  * 
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14. package java.awt;
  15.  
  16. import java.util.Hashtable;
  17. import java.util.Vector;
  18.  
  19. class GridBagLayoutInfo implements java.io.Serializable {
  20.   int width, height;        /* number of cells horizontally, vertically */
  21.   int startx, starty;        /* starting point for layout */
  22.   int minWidth[];        /* largest minWidth in each column */
  23.   int minHeight[];        /* largest minHeight in each row */
  24.   double weightX[];        /* largest weight in each column */
  25.   double weightY[];        /* largest weight in each row */
  26.  
  27.   GridBagLayoutInfo () {
  28.     minWidth = new int[GridBagLayout.MAXGRIDSIZE];
  29.     minHeight = new int[GridBagLayout.MAXGRIDSIZE];
  30.     weightX = new double[GridBagLayout.MAXGRIDSIZE];
  31.     weightY = new double[GridBagLayout.MAXGRIDSIZE];
  32.   }
  33. }
  34.  
  35. /**
  36.  * The <code>GridBagLayout</code> class is a flexible layout 
  37.  * manager that aligns components vertically and horizontally,
  38.  * without requiring that the components be of the same size.
  39.  * Each <code>GridBagLayout</code> object maintains a dynamic 
  40.  * rectangular grid of cells, with each component occupying 
  41.  * one or more cells, called its <em>display area</em>.
  42.  * <p>
  43.  * Each component managed by a grid bag layout is associated 
  44.  * with an instance of 
  45.  * <a href="java.awt.GridBagConstraints.html"><code>GridBagConstraints</code></a> 
  46.  * that specifies how the component is laid out within its display area.
  47.  * <p>
  48.  * How a <code>GridBagLayout</code> object places a set of components
  49.  * depends on the <code>GridBagConstraints</code> object associated 
  50.  * with each component, and on the minimum size 
  51.  * and the preferred size of the components' containers.
  52.  * <p>
  53.  * To use a grid bag layout effectively, you must customize one or more 
  54.  * of the <code>GridBagConstraints</code> objects that are associated 
  55.  * with its components. You customize a <code>GridBagConstraints</code> 
  56.  * object by setting one or more of its instance variables:
  57.  * <p>
  58.  * <dl>
  59.  * <dt><a href="java.awt.GridBagConstraints.html#gridx"><code>gridx</code></a>,
  60.  * <a href="java.awt.GridBagConstraints.html#gridy"><code>gridy</code></a>
  61.  * <dd>Specifies the cell at the upper left of the component's display area,
  62.  * where the upper-left-most cell has address 
  63.  * <code>gridx = 0</code>, 
  64.  * <code>gridy = 0</code>. 
  65.  * Use <code>GridBagConstraints.RELATIVE</code> (the default value)
  66.  * to specify that the component be just placed
  67.  * just to the right of (for <code>gridx</code>)
  68.  * or just below (for <code>gridy</code>)
  69.  * the component that was added to the container
  70.  * just before this component was added.
  71.  * <dt><a href="java.awt.GridBagConstraints.html#gridwidth"><code>gridwidth</code></a>,
  72.  * <a href="java.awt.GridBagConstraints.html#gridheight"><code>gridheight</code></a>
  73.  * <dd>Specifies the number of cells in a row (for <code>gridwidth</code>)
  74.  * or column (for <code>gridheight</code>)
  75.  * in the component's display area.
  76.  * The default value is 1.
  77.  * Use <code>GridBagConstraints.REMAINDER</code> to specify 
  78.  * that the component be the last one in its row (for <code>gridwidth</code>)
  79.  * or column (for <code>gridheight</code>).
  80.  * Use <code>GridBagConstraints.RELATIVE</code> to specify 
  81.  * that the component be the next to last one
  82.  * in its row (for <code>gridwidth</code>) 
  83.  * or column (for <code>gridheight</code>).
  84.  * <dt><a href="java.awt.GridBagConstraints.html#fill"><code>fill</code></a>
  85.  * <dd>Used when the component's display area
  86.  * is larger than the component's requested size
  87.  * to determine whether (and how) to resize the component.
  88.  * Possible values are
  89.  * <code>GridBagConstraints.NONE</code> (the default),
  90.  * <code>GridBagConstraints.HORIZONTAL</code> 
  91.  * (make the component wide enough to fill its display area
  92.  * horizontally, but don't change its height),
  93.  * <code>GridBagConstraints.VERTICAL</code> 
  94.  * (make the component tall enough to fill its display area 
  95.  * vertically, but don't change its width), and 
  96.  * <code>GridBagConstraints.BOTH</code> 
  97.  * (make the component fill its display area entirely). 
  98.  * <dt><a href="java.awt.GridBagConstraints.html#ipadx"><code>ipadx</code></a>,
  99.  * <a href="java.awt.GridBagConstraints.html#ipady"><code>ipady</code></a>
  100.  * <dd>Specifies the component's internal padding within the layout, 
  101.  * how much to add to the minimum size of the component.
  102.  * The width of the component will be at least its minimum width 
  103.  * plus <code>(ipadx * 2)</code> pixels (since the padding 
  104.  * applies to both sides of the component). Similarly, the height of 
  105.  * the component will be at least the minimum height plus 
  106.  * <code>(ipady * 2)</code> pixels.
  107.  * <dt><a href="java.awt.GridBagConstraints.html#insets"><code>insets</code></a>
  108.  * <dd>Specifies the component's external padding, the minimum
  109.  * amount of space between the component and the edges of its display area.
  110.  * <dt><a href="java.awt.GridBagConstraints.html#anchor"><code>anchor</code></a>
  111.  * <dd>Used when the component is smaller than its display area
  112.  * to determine where (within the display area) to place the component.
  113.  * Valid values are 
  114.  * <code>GridBagConstraints.CENTER</code> (the default), 
  115.  * <code>GridBagConstraints.NORTH</code>, 
  116.  * <code>GridBagConstraints.NORTHEAST</code>, 
  117.  * <code>GridBagConstraints.EAST</code>, 
  118.  * <code>GridBagConstraints.SOUTHEAST</code>, 
  119.  * <code>GridBagConstraints.SOUTH</code>, 
  120.  * <code>GridBagConstraints.SOUTHWEST</code>, 
  121.  * <code>GridBagConstraints.WEST</code>, and 
  122.  * <code>GridBagConstraints.NORTHWEST</code>. 
  123.  * <dt><a href="java.awt.GridBagConstraints.html#weightx"><code>weightx</code></a>,
  124.  * <a href="java.awt.GridBagConstraints.html#weighty"><code>weighty</code></a>
  125.  * <dd>Used to determine how to distribute space, which is 
  126.  * important for specifying resizing behavior.
  127.  * Unless you specify a weight for at least one component 
  128.  * in a row (<code>weightx</code>) and column (<code>weighty</code>), 
  129.  * all the components clump together in the center of their container.
  130.  * This is because when the weight is zero (the default),
  131.  * the <code>GridBagLayout</code> object puts any extra space 
  132.  * between its grid of cells and the edges of the container.
  133.  * </dl>
  134.  * <p>
  135.  * The following figure shows ten components (all buttons)
  136.  * managed by a grid bag layout:
  137.  * <p>
  138.  * <img src="images-awt/GridBagLayout-1.gif" 
  139.  * ALIGN=center HSPACE=10 VSPACE=7>
  140.  * <p>
  141.  * Each of the ten components has the <code>fill</code> field 
  142.  * of its associated <code>GridBagConstraints</code> object 
  143.  * set to <code>GridBagConstraints.BOTH</code>.
  144.  * In addition, the components have the following non-default constraints:
  145.  * <p>
  146.  * <ul>
  147.  * <li>Button1, Button2, Button3: <code>weightx = 1.0</code> 
  148.  * <li>Button4: <code>weightx = 1.0</code>, 
  149.  * <code>gridwidth = GridBagConstraints.REMAINDER</code> 
  150.  * <li>Button5: <code>gridwidth = GridBagConstraints.REMAINDER</code> 
  151.  * <li>Button6: <code>gridwidth = GridBagConstraints.RELATIVE</code> 
  152.  * <li>Button7: <code>gridwidth = GridBagConstraints.REMAINDER</code> 
  153.  * <li>Button8: <code>gridheight = 2</code>, 
  154.  * <code>weighty = 1.0</code> 
  155.  * <li>Button9, Button 10: 
  156.  * <code>gridwidth = GridBagConstraints.REMAINDER</code> 
  157.  * </ul>
  158.  * <p>
  159.  * Here is the code that implements the example shown above:
  160.  * <p>
  161.  * <hr><blockquote><pre>
  162.  * import java.awt.*;
  163.  * import java.util.*;
  164.  * import java.applet.Applet;
  165.  * 
  166.  * public class GridBagEx1 extends Applet {
  167.  * 
  168.  *     protected void makebutton(String name,
  169.  *                               GridBagLayout gridbag,
  170.  *                               GridBagConstraints c) {
  171.  *         Button button = new Button(name);
  172.  *         gridbag.setConstraints(button, c);
  173.  *         add(button);
  174.  *     }
  175.  * 
  176.  *     public void init() {
  177.  *         GridBagLayout gridbag = new GridBagLayout();
  178.  *         GridBagConstraints c = new GridBagConstraints();
  179.  *  
  180.  *         setFont(new Font("Helvetica", Font.PLAIN, 14));
  181.  *         setLayout(gridbag);
  182.  *    
  183.  *         c.fill = GridBagConstraints.BOTH;
  184.  *         c.weightx = 1.0;
  185.  *         makebutton("Button1", gridbag, c);
  186.  *         makebutton("Button2", gridbag, c);
  187.  *         makebutton("Button3", gridbag, c);
  188.  *     
  189.  *            c.gridwidth = GridBagConstraints.REMAINDER; //end row
  190.  *         makebutton("Button4", gridbag, c);
  191.  *     
  192.  *         c.weightx = 0.0;           //reset to the default
  193.  *         makebutton("Button5", gridbag, c); //another row
  194.  *     
  195.  *        c.gridwidth = GridBagConstraints.RELATIVE; //next-to-last in row
  196.  *         makebutton("Button6", gridbag, c);
  197.  *     
  198.  *        c.gridwidth = GridBagConstraints.REMAINDER; //end row
  199.  *         makebutton("Button7", gridbag, c);
  200.  *     
  201.  *        c.gridwidth = 1;              //reset to the default
  202.  *        c.gridheight = 2;
  203.  *         c.weighty = 1.0;
  204.  *         makebutton("Button8", gridbag, c);
  205.  *     
  206.  *         c.weighty = 0.0;           //reset to the default
  207.  *        c.gridwidth = GridBagConstraints.REMAINDER; //end row
  208.  *        c.gridheight = 1;           //reset to the default
  209.  *         makebutton("Button9", gridbag, c);
  210.  *         makebutton("Button10", gridbag, c);
  211.  *     
  212.  *         setSize(300, 100);
  213.  *     }
  214.  *     
  215.  *     public static void main(String args[]) {
  216.  *        Frame f = new Frame("GridBag Layout Example");
  217.  *        GridBagEx1 ex1 = new GridBagEx1();
  218.  *     
  219.  *        ex1.init();
  220.  *     
  221.  *        f.add("Center", ex1);
  222.  *        f.pack();
  223.  *        f.setSize(f.getPreferredSize());
  224.  *        f.show();
  225.  *     }
  226.  * }
  227.  * </pre></blockquote><hr>
  228.  * <p>
  229.  * @version 1.5, 16 Nov 1995
  230.  * @author Doug Stein
  231.  * @see       java.awt.GridBagConstraints
  232.  * @since     JDK1.0
  233.  */
  234. public class GridBagLayout implements LayoutManager2,
  235.                       java.io.Serializable {
  236.  
  237.     /**
  238.      * The maximum number of grid positions (both horizontally and 
  239.      * vertically) that can be laid out by the grid bag layout. 
  240.      * @since     JDK1.0
  241.      */
  242.   protected static final int MAXGRIDSIZE = 512;
  243.  
  244.     /**
  245.      * The smallest grid that can be laid out by the grid bag layout. 
  246.      * @since     JDK1.0
  247.      */
  248.   protected static final int MINSIZE = 1;
  249.   protected static final int PREFERREDSIZE = 2;
  250.  
  251.   protected Hashtable comptable;
  252.   protected GridBagConstraints defaultConstraints;
  253.   protected GridBagLayoutInfo layoutInfo;
  254.  
  255.   public int columnWidths[];
  256.   public int rowHeights[];
  257.   public double columnWeights[];
  258.   public double rowWeights[];
  259.  
  260.   /**
  261.    * Creates a grid bag layout manager.
  262.    * @since       JDK1.0
  263.    */
  264.   public GridBagLayout () {
  265.     comptable = new Hashtable();
  266.     defaultConstraints = new GridBagConstraints();
  267.   }
  268.  
  269.   /**
  270.    * Sets the constraints for the specified component in this layout.
  271.    * @param       comp the component to be modified.
  272.    * @param       constraints the constraints to be applied.
  273.    * @since       JDK1.0
  274.    */
  275.   public void setConstraints(Component comp, GridBagConstraints constraints) {
  276.     comptable.put(comp, constraints.clone());
  277.   }
  278.  
  279.   /**
  280.    * Gets the constraints for the specified component.  A copy of
  281.    * the actual <code>GridBagConstraints</code> object is returned.
  282.    * @param       comp the component to be queried.
  283.    * @return      the constraint for the specified component in this 
  284.    *                  grid bag layout; a copy of the actual constraint 
  285.    *                  object is returned.
  286.    * @since       JDK1.0
  287.    */
  288.   public GridBagConstraints getConstraints(Component comp) {
  289.     GridBagConstraints constraints = (GridBagConstraints)comptable.get(comp);
  290.     if (constraints == null) {
  291.       setConstraints(comp, defaultConstraints);
  292.       constraints = (GridBagConstraints)comptable.get(comp);
  293.     }
  294.     return (GridBagConstraints)constraints.clone();
  295.   }
  296.  
  297.   /**
  298.    * Retrieves the constraints for the specified component.  
  299.    * The return value is not a copy, but is the actual 
  300.    * <code>GridBagConstraints</code> object used by the layout mechanism. 
  301.    * @param       comp the component to be queried
  302.    * @return      the contraints for the specified component.
  303.    * @since       JDK1.0
  304.    */
  305.   protected GridBagConstraints lookupConstraints(Component comp) {
  306.     GridBagConstraints constraints = (GridBagConstraints)comptable.get(comp);
  307.     if (constraints == null) {
  308.       setConstraints(comp, defaultConstraints);
  309.       constraints = (GridBagConstraints)comptable.get(comp);
  310.     }
  311.     return constraints;
  312.   }
  313.  
  314.     /**
  315.      * Determines the origin of the layout grid. 
  316.      * Most applications do not call this method directly.
  317.      * @return     the origin of the cell in the top-left 
  318.      *                    corner of the layout grid.
  319.      * @since      JDK1.1
  320.      */
  321.   public Point getLayoutOrigin () {
  322.     Point origin = new Point(0,0);
  323.     if (layoutInfo != null) {
  324.       origin.x = layoutInfo.startx;
  325.       origin.y = layoutInfo.starty;
  326.     }
  327.     return origin;
  328.   }
  329.  
  330.     /**
  331.      * Determines column widths and row heights for the layout grid.
  332.      * <p>
  333.      * Most applications do not call this method directly.
  334.      * @return     an array of two arrays, containing the widths 
  335.      *                       of the layout columns and
  336.      *                       the heights of the layout rows.
  337.      * @since      JDK1.1
  338.      */
  339.   public int [][] getLayoutDimensions () {
  340.     if (layoutInfo == null)
  341.       return new int[2][0];
  342.  
  343.     int dim[][] = new int [2][];
  344.     dim[0] = new int[layoutInfo.width];
  345.     dim[1] = new int[layoutInfo.height];
  346.  
  347.     System.arraycopy(layoutInfo.minWidth, 0, dim[0], 0, layoutInfo.width);
  348.     System.arraycopy(layoutInfo.minHeight, 0, dim[1], 0, layoutInfo.height);
  349.  
  350.     return dim;
  351.   }
  352.  
  353.     /**
  354.      * Determines the weights of the layout grid's columns and rows.
  355.      * Weights are used to calculate how much a given column or row
  356.      * stretches beyond its preferred size, if the layout has extra
  357.      * room to fill.
  358.      * <p>
  359.      * Most applications do not call this method directly.
  360.      * @return      an array of two arrays, representing the 
  361.      *                    horizontal weights of the layout columns 
  362.      *                    and the vertical weights of the layout rows.
  363.      * @since       JDK1.1
  364.      */
  365.   public double [][] getLayoutWeights () {
  366.     if (layoutInfo == null)
  367.       return new double[2][0];
  368.  
  369.     double weights[][] = new double [2][];
  370.     weights[0] = new double[layoutInfo.width];
  371.     weights[1] = new double[layoutInfo.height];
  372.  
  373.     System.arraycopy(layoutInfo.weightX, 0, weights[0], 0, layoutInfo.width);
  374.     System.arraycopy(layoutInfo.weightY, 0, weights[1], 0, layoutInfo.height);
  375.  
  376.     return weights;
  377.   }
  378.  
  379.     /**
  380.      * Determines which cell in the layout grid contains the point
  381.      * specified by <code>(x, y)</code>. Each cell is identified 
  382.      * by its column index (ranging from 0 to the number of columns 
  383.      * minus 1) and its row index (ranging from 0 to the number of 
  384.      * rows minus 1).  
  385.      * <p>
  386.      * If the <code>(x, y)</code> point lies 
  387.      * outside the grid, the following rules are used.  
  388.      * The column index is returned as zero if <code>x</code> lies to the
  389.      * left of the layout, and as the number of columns if <code>x</code> lies
  390.      * to the right of the layout. The row index is returned as zero
  391.      * if <code>y</code> lies above the layout, 
  392.      * and as the number of rows if <code>y</code> lies
  393.      * below the layout.
  394.      * @param      x    the <i>x</i> coordinate of a point.
  395.      * @param      y    the <i>y</i> coordinate of a point.
  396.      * @return     an ordered pair of indexes that indicate which cell 
  397.      *             in the layout grid contains the point 
  398.      *             (<i>x</i>, <i>y</i>).
  399.      * @since      JDK1.1
  400.      */
  401.   public Point location(int x, int y) {
  402.     Point loc = new Point(0,0);
  403.     int i, d;
  404.  
  405.     if (layoutInfo == null)
  406.       return loc;
  407.  
  408.     d = layoutInfo.startx;
  409.     for (i=0; i<layoutInfo.width; i++) {
  410.       d += layoutInfo.minWidth[i];
  411.       if (d > x)
  412.     break;
  413.     }
  414.     loc.x = i;
  415.  
  416.     d = layoutInfo.starty;
  417.     for (i=0; i<layoutInfo.height; i++) {
  418.       d += layoutInfo.minHeight[i];
  419.       if (d > y)
  420.     break;
  421.     }
  422.     loc.y = i;
  423.  
  424.     return loc;
  425.   }
  426.  
  427.   /**
  428.    * Adds the specified component with the specified name to the layout.
  429.    * @param      name         the name of the component.
  430.    * @param      comp         the component to be added.
  431.    * @since      JDK1.0
  432.    */
  433.   public void addLayoutComponent(String name, Component comp) {
  434.   }
  435.  
  436.     /**
  437.      * Adds the specified component to the layout, using the specified
  438.      * constraint object.
  439.      * @param      comp         the component to be added.
  440.      * @param      constraints  an object that determines how 
  441.      *                              the component is added to the layout.
  442.      * @since      JDK1.0
  443.      */
  444.     public void addLayoutComponent(Component comp, Object constraints) {
  445.       if (constraints instanceof GridBagConstraints) {
  446.         setConstraints(comp, (GridBagConstraints)constraints);
  447.     }else if (constraints instanceof String){
  448.         //Netscape : Just Ignore it
  449.     }else if (constraints != null) {
  450.         throw new IllegalArgumentException("cannot add to layout: constraint must be a GridBagConstraint");
  451.     }
  452.     }
  453.  
  454.   /**
  455.      * Removes the specified component from this layout. 
  456.      * <p>
  457.      * Most applications do not call this method directly.  
  458.      * @param    comp   the component to be removed.
  459.      * @see      java.awt.Container#remove(java.awt.Component)
  460.      * @see      java.awt.Container#removeAll()
  461.      * @since    JDK1.0
  462.    */
  463.   public void removeLayoutComponent(Component comp) {
  464.   }
  465.  
  466.   /** 
  467.      * Determines the preferred size of the <code>target</code> 
  468.      * container using this grid bag layout. 
  469.      * <p>
  470.      * Most applications do not call this method directly.
  471.      * @param     target   the container in which to do the layout.
  472.      * @see       java.awt.Container#getPreferredSize
  473.      * @since     JDK1.0
  474.    */
  475.   public Dimension preferredLayoutSize(Container parent) {
  476.     GridBagLayoutInfo info = GetLayoutInfo(parent, PREFERREDSIZE);
  477.     return GetMinSize(parent, info);
  478.   }
  479.  
  480.   /**
  481.      * Determines the minimum size of the <code>target</code> container 
  482.      * using this grid bag layout. 
  483.      * <p>
  484.      * Most applications do not call this method directly. 
  485.      * @param     target   the container in which to do the layout.
  486.      * @see       java.awt.Container#doLayout
  487.      * @since     JDK1.0
  488.    */
  489.   public Dimension minimumLayoutSize(Container parent) {
  490.     GridBagLayoutInfo info = GetLayoutInfo(parent, MINSIZE);
  491.     return GetMinSize(parent, info);
  492.   }
  493.  
  494.     /**
  495.      * Returns the maximum dimensions for this layout given the components
  496.      * in the specified target container.
  497.      * @param target the component which needs to be laid out
  498.      * @see Container
  499.      * @see #minimumLayoutSize
  500.      * @see #preferredLayoutSize
  501.      */
  502.     public Dimension maximumLayoutSize(Container target) {
  503.     return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
  504.     }
  505.  
  506.     /**
  507.      * Returns the alignment along the x axis.  This specifies how
  508.      * the component would like to be aligned relative to other 
  509.      * components.  The value should be a number between 0 and 1
  510.      * where 0 represents alignment along the origin, 1 is aligned
  511.      * the furthest away from the origin, 0.5 is centered, etc.
  512.      */
  513.     public float getLayoutAlignmentX(Container parent) {
  514.     return 0.5f;
  515.     }
  516.  
  517.     /**
  518.      * Returns the alignment along the y axis.  This specifies how
  519.      * the component would like to be aligned relative to other 
  520.      * components.  The value should be a number between 0 and 1
  521.      * where 0 represents alignment along the origin, 1 is aligned
  522.      * the furthest away from the origin, 0.5 is centered, etc.
  523.      */
  524.     public float getLayoutAlignmentY(Container parent) {
  525.     return 0.5f;
  526.     }
  527.  
  528.     /**
  529.      * Invalidates the layout, indicating that if the layout manager
  530.      * has cached information it should be discarded.
  531.      */
  532.     public void invalidateLayout(Container target) {
  533.     }
  534.                       
  535.   /** 
  536.    * Lays out the specified container using this grid bag layout.
  537.    * This method reshapes components in the specified container in 
  538.    * order to satisfy the contraints of this <code>GridBagLayout</code> 
  539.    * object.
  540.    * <p>
  541.    * Most applications do not call this method directly.
  542.    * @param parent the container in which to do the layout.
  543.    * @see java.awt.Container
  544.    * @see java.awt.Container#doLayout
  545.    * @since JDK1.0
  546.    */
  547.   public void layoutContainer(Container parent) {
  548.     ArrangeGrid(parent);
  549.   }
  550.  
  551.   /**
  552.      * Returns a string representation of this grid bag layout's values.
  553.      * @return     a string representation of this grid bag layout.
  554.      * @since      JDK1.0
  555.    */
  556.   public String toString() {
  557.     return getClass().getName();
  558.   }
  559.  
  560.   /**
  561.    * Print the layout information.  Useful for debugging.
  562.    */
  563.  
  564.   /* DEBUG
  565.    *
  566.    *  protected void DumpLayoutInfo(GridBagLayoutInfo s) {
  567.    *    int x;
  568.    *
  569.    *    System.out.println("Col\tWidth\tWeight");
  570.    *    for (x=0; x<s.width; x++) {
  571.    *      System.out.println(x + "\t" +
  572.    *             s.minWidth[x] + "\t" +
  573.    *             s.weightX[x]);
  574.    *    }
  575.    *    System.out.println("Row\tHeight\tWeight");
  576.    *    for (x=0; x<s.height; x++) {
  577.    *      System.out.println(x + "\t" +
  578.    *             s.minHeight[x] + "\t" +
  579.    *             s.weightY[x]);
  580.    *    }
  581.    *  }
  582.    */
  583.  
  584.   /**
  585.    * Print the layout constraints.  Useful for debugging.
  586.    */
  587.  
  588.   /* DEBUG
  589.    *
  590.    *  protected void DumpConstraints(GridBagConstraints constraints) {
  591.    *    System.out.println(
  592.    *               "wt " +
  593.    *               constraints.weightx +
  594.    *               " " +
  595.    *               constraints.weighty +
  596.    *               ", " +
  597.    *
  598.    *               "box " +
  599.    *               constraints.gridx +
  600.    *               " " +
  601.    *               constraints.gridy +
  602.    *               " " +
  603.    *               constraints.gridwidth +
  604.    *               " " +
  605.    *               constraints.gridheight +
  606.    *               ", " +
  607.    *
  608.    *               "min " +
  609.    *               constraints.minWidth +
  610.    *               " " +
  611.    *               constraints.minHeight +
  612.    *               ", " +
  613.    *
  614.    *               "pad " +
  615.    *               constraints.insets.bottom +
  616.    *               " " +
  617.    *               constraints.insets.left +
  618.    *               " " +
  619.    *               constraints.insets.right +
  620.    *               " " +
  621.    *               constraints.insets.top +
  622.    *               " " +
  623.    *               constraints.ipadx +
  624.    *               " " +
  625.    *               constraints.ipady);
  626.    *  }
  627.    */
  628.  
  629.   /*
  630.    * Fill in an instance of the above structure for the current set
  631.    * of managed children.  This requires three passes through the
  632.    * set of children:
  633.    *
  634.    * 1) Figure out the dimensions of the layout grid
  635.    * 2) Determine which cells the components occupy
  636.    * 3) Distribute the weights and min sizes amoung the rows/columns.
  637.    *
  638.    * This also caches the minsizes for all the children when they are
  639.    * first encountered (so subsequent loops don't need to ask again).
  640.    */
  641.   
  642.   protected GridBagLayoutInfo GetLayoutInfo(Container parent, int sizeflag) {
  643.    synchronized (parent.getTreeLock()) {
  644.     GridBagLayoutInfo r = new GridBagLayoutInfo();
  645.     Component comp;
  646.     GridBagConstraints constraints;
  647.     Dimension d;
  648.     Component components[] = parent.getComponents();
  649.  
  650.     int compindex, i, j, k, px, py, pixels_diff, nextSize;
  651.     int curX, curY, curWidth, curHeight, curRow, curCol;
  652.     double weight_diff, weight, start, size;
  653.     int xMax[], yMax[];
  654.  
  655.     /*
  656.      * Pass #1
  657.      *
  658.      * Figure out the dimensions of the layout grid (use a value of 1 for
  659.      * zero or negative widths and heights).
  660.      */
  661.     
  662.     r.width = r.height = 0;
  663.     curRow = curCol = -1;
  664.     xMax = new int[MAXGRIDSIZE];
  665.     yMax = new int[MAXGRIDSIZE];
  666.  
  667.     for (compindex = 0 ; compindex < components.length ; compindex++) {
  668.       comp = components[compindex];
  669.       if (!comp.isVisible())
  670.     continue;
  671.       constraints = lookupConstraints(comp);
  672.       
  673.       curX = constraints.gridx;
  674.       curY = constraints.gridy;
  675.       curWidth = constraints.gridwidth;
  676.       if (curWidth <= 0)
  677.     curWidth = 1;
  678.       curHeight = constraints.gridheight;
  679.       if (curHeight <= 0)
  680.     curHeight = 1;
  681.       
  682.       /* If x or y is negative, then use relative positioning: */
  683.       if (curX < 0 && curY < 0) {
  684.     if (curRow >= 0)
  685.       curY = curRow;
  686.     else if (curCol >= 0)
  687.       curX = curCol;
  688.     else
  689.       curY = 0;
  690.       }
  691.       if (curX < 0) {
  692.     px = 0;
  693.     for (i = curY; i < (curY + curHeight); i++)
  694.       px = Math.max(px, xMax[i]);
  695.     
  696.     curX = px - curX - 1;
  697.     if(curX < 0)
  698.       curX = 0;
  699.       }
  700.       else if (curY < 0) {
  701.     py = 0;
  702.     for (i = curX; i < (curX + curWidth); i++)
  703.       py = Math.max(py, yMax[i]);
  704.     
  705.     curY = py - curY - 1;
  706.     if(curY < 0)
  707.       curY = 0;
  708.       }
  709.       
  710.       /* Adjust the grid width and height */
  711.       for (px = curX + curWidth; r.width < px; r.width++);
  712.       for (py = curY + curHeight; r.height < py; r.height++);
  713.       
  714.       /* Adjust the xMax and yMax arrays */
  715.       for (i = curX; i < (curX + curWidth); i++) { yMax[i] = py; }
  716.       for (i = curY; i < (curY + curHeight); i++) { xMax[i] = px; }
  717.       
  718.       /* Cache the current slave's size. */
  719.       if (sizeflag == PREFERREDSIZE)
  720.     d = comp.getPreferredSize();
  721.       else
  722.     d = comp.getMinimumSize();
  723.       constraints.minWidth = d.width;
  724.       constraints.minHeight = d.height;
  725.       
  726.       /* Zero width and height must mean that this is the last item (or
  727.        * else something is wrong). */
  728.       if (constraints.gridheight == 0 && constraints.gridwidth == 0)
  729.     curRow = curCol = -1;
  730.       
  731.       /* Zero width starts a new row */
  732.       if (constraints.gridheight == 0 && curRow < 0)
  733.     curCol = curX + curWidth;
  734.       
  735.       /* Zero height starts a new column */
  736.       else if (constraints.gridwidth == 0 && curCol < 0)
  737.     curRow = curY + curHeight;
  738.     }
  739.     
  740.     /*
  741.      * Apply minimum row/column dimensions
  742.      */
  743.     if (columnWidths != null && r.width < columnWidths.length)
  744.       r.width = columnWidths.length;
  745.     if (rowHeights != null && r.height < rowHeights.length)
  746.       r.height = rowHeights.length;
  747.  
  748.     /*
  749.      * Pass #2
  750.      *
  751.      * Negative values for gridX are filled in with the current x value.
  752.      * Negative values for gridY are filled in with the current y value.
  753.      * Negative or zero values for gridWidth and gridHeight end the current
  754.      *  row or column, respectively.
  755.      */
  756.     
  757.     curRow = curCol = -1;
  758.     xMax = new int[MAXGRIDSIZE];
  759.     yMax = new int[MAXGRIDSIZE];
  760.     
  761.     for (compindex = 0 ; compindex < components.length ; compindex++) {
  762.       comp = components[compindex];
  763.       if (!comp.isVisible())
  764.     continue;
  765.       constraints = lookupConstraints(comp);
  766.       
  767.       curX = constraints.gridx;
  768.       curY = constraints.gridy;
  769.       curWidth = constraints.gridwidth;
  770.       curHeight = constraints.gridheight;
  771.       
  772.       /* If x or y is negative, then use relative positioning: */
  773.       if (curX < 0 && curY < 0) {
  774.     if(curRow >= 0)
  775.       curY = curRow;
  776.     else if(curCol >= 0)
  777.       curX = curCol;
  778.     else
  779.       curY = 0;
  780.       }
  781.       
  782.       if (curX < 0) {
  783.     if (curHeight <= 0) {
  784.       curHeight += r.height - curY;
  785.       if (curHeight < 1)
  786.         curHeight = 1;
  787.     }
  788.     
  789.     px = 0;
  790.     for (i = curY; i < (curY + curHeight); i++)
  791.       px = Math.max(px, xMax[i]);
  792.     
  793.     curX = px - curX - 1;
  794.     if(curX < 0)
  795.       curX = 0;
  796.       }
  797.       else if (curY < 0) {
  798.     if (curWidth <= 0) {
  799.       curWidth += r.width - curX;
  800.       if (curWidth < 1)
  801.         curWidth = 1;
  802.     }
  803.     
  804.     py = 0;
  805.     for (i = curX; i < (curX + curWidth); i++)
  806.       py = Math.max(py, yMax[i]);
  807.     
  808.     curY = py - curY - 1;
  809.     if(curY < 0)
  810.       curY = 0;
  811.       }
  812.       
  813.       if (curWidth <= 0) {
  814.     curWidth += r.width - curX;
  815.     if (curWidth < 1)
  816.       curWidth = 1;
  817.       }
  818.       
  819.       if (curHeight <= 0) {
  820.     curHeight += r.height - curY;
  821.     if (curHeight < 1)
  822.       curHeight = 1;
  823.       }
  824.       
  825.       px = curX + curWidth;
  826.       py = curY + curHeight;
  827.       
  828.       for (i = curX; i < (curX + curWidth); i++) { yMax[i] = py; }
  829.       for (i = curY; i < (curY + curHeight); i++) { xMax[i] = px; }
  830.       
  831.       /* Make negative sizes start a new row/column */
  832.       if (constraints.gridheight == 0 && constraints.gridwidth == 0)
  833.     curRow = curCol = -1;
  834.       if (constraints.gridheight == 0 && curRow < 0)
  835.     curCol = curX + curWidth;
  836.       else if (constraints.gridwidth == 0 && curCol < 0)
  837.         curRow = curY + curHeight;
  838.       
  839.       /* Assign the new values to the gridbag slave */
  840.       constraints.tempX = curX;
  841.       constraints.tempY = curY;
  842.       constraints.tempWidth = curWidth;
  843.       constraints.tempHeight = curHeight;
  844.     }
  845.     
  846.     /*
  847.      * Apply minimum row/column dimensions and weights
  848.      */
  849.     if (columnWidths != null)
  850.       System.arraycopy(columnWidths, 0, r.minWidth, 0, columnWidths.length);
  851.     if (rowHeights != null)
  852.       System.arraycopy(rowHeights, 0, r.minHeight, 0, rowHeights.length);
  853.     if (columnWeights != null)
  854.       System.arraycopy(columnWeights, 0, r.weightX, 0, columnWeights.length);
  855.     if (rowWeights != null)
  856.       System.arraycopy(rowWeights, 0, r.weightY, 0, rowWeights.length);
  857.  
  858.     /*
  859.      * Pass #3
  860.      *
  861.      * Distribute the minimun widths and weights:
  862.      */
  863.     
  864.     nextSize = Integer.MAX_VALUE;
  865.     
  866.     for (i = 1;
  867.      i != Integer.MAX_VALUE;
  868.      i = nextSize, nextSize = Integer.MAX_VALUE) {
  869.       for (compindex = 0 ; compindex < components.length ; compindex++) {
  870.     comp = components[compindex];
  871.     if (!comp.isVisible())
  872.       continue;
  873.     constraints = lookupConstraints(comp);
  874.       
  875.     if (constraints.tempWidth == i) {
  876.       px = constraints.tempX + constraints.tempWidth; /* right column */
  877.       
  878.       /* 
  879.        * Figure out if we should use this slave\'s weight.  If the weight
  880.        * is less than the total weight spanned by the width of the cell,
  881.        * then discard the weight.  Otherwise split the difference
  882.        * according to the existing weights.
  883.        */
  884.       
  885.       weight_diff = constraints.weightx;
  886.       for (k = constraints.tempX; k < px; k++)
  887.         weight_diff -= r.weightX[k];
  888.       if (weight_diff > 0.0) {
  889.         weight = 0.0;
  890.         for (k = constraints.tempX; k < px; k++)
  891.           weight += r.weightX[k];
  892.         for (k = constraints.tempX; weight > 0.0 && k < px; k++) {
  893.           double wt = r.weightX[k];
  894.           double dx = (wt * weight_diff) / weight;
  895.           r.weightX[k] += dx;
  896.           weight_diff -= dx;
  897.           weight -= wt;
  898.         }
  899.         /* Assign the remainder to the rightmost cell */
  900.         r.weightX[px-1] += weight_diff;
  901.       }
  902.       
  903.       /*
  904.        * Calculate the minWidth array values.
  905.        * First, figure out how wide the current slave needs to be.
  906.        * Then, see if it will fit within the current minWidth values.
  907.        * If it will not fit, add the difference according to the
  908.        * weightX array.
  909.        */
  910.       
  911.       pixels_diff =
  912.         constraints.minWidth + constraints.ipadx +
  913.         constraints.insets.left + constraints.insets.right;
  914.  
  915.       for (k = constraints.tempX; k < px; k++)
  916.         pixels_diff -= r.minWidth[k];
  917.       if (pixels_diff > 0) {
  918.         weight = 0.0;
  919.         for (k = constraints.tempX; k < px; k++)
  920.           weight += r.weightX[k];
  921.         for (k = constraints.tempX; weight > 0.0 && k < px; k++) {
  922.           double wt = r.weightX[k];
  923.           int dx = (int)((wt * ((double)pixels_diff)) / weight);
  924.           r.minWidth[k] += dx;
  925.           pixels_diff -= dx;
  926.           weight -= wt;
  927.         }
  928.         /* Any leftovers go into the rightmost cell */
  929.         r.minWidth[px-1] += pixels_diff;
  930.       }
  931.     }
  932.     else if (constraints.tempWidth > i && constraints.tempWidth < nextSize)
  933.       nextSize = constraints.tempWidth;
  934.     
  935.     
  936.     if (constraints.tempHeight == i) {
  937.       py = constraints.tempY + constraints.tempHeight; /* bottom row */
  938.       
  939.       /* 
  940.        * Figure out if we should use this slave\'s weight.  If the weight
  941.        * is less than the total weight spanned by the height of the cell,
  942.        * then discard the weight.  Otherwise split it the difference
  943.        * according to the existing weights.
  944.        */
  945.       
  946.       weight_diff = constraints.weighty;
  947.       for (k = constraints.tempY; k < py; k++)
  948.         weight_diff -= r.weightY[k];
  949.       if (weight_diff > 0.0) {
  950.         weight = 0.0;
  951.         for (k = constraints.tempY; k < py; k++)
  952.           weight += r.weightY[k];
  953.         for (k = constraints.tempY; weight > 0.0 && k < py; k++) {
  954.           double wt = r.weightY[k];
  955.           double dy = (wt * weight_diff) / weight;
  956.           r.weightY[k] += dy;
  957.           weight_diff -= dy;
  958.           weight -= wt;
  959.         }
  960.         /* Assign the remainder to the bottom cell */
  961.         r.weightY[py-1] += weight_diff;
  962.       }
  963.       
  964.       /*
  965.        * Calculate the minHeight array values.
  966.        * First, figure out how tall the current slave needs to be.
  967.        * Then, see if it will fit within the current minHeight values.
  968.        * If it will not fit, add the difference according to the
  969.        * weightY array.
  970.        */
  971.       
  972.       pixels_diff =
  973.         constraints.minHeight + constraints.ipady +
  974.         constraints.insets.top + constraints.insets.bottom;
  975.       for (k = constraints.tempY; k < py; k++)
  976.         pixels_diff -= r.minHeight[k];
  977.       if (pixels_diff > 0) {
  978.         weight = 0.0;
  979.         for (k = constraints.tempY; k < py; k++)
  980.           weight += r.weightY[k];
  981.         for (k = constraints.tempY; weight > 0.0 && k < py; k++) {
  982.           double wt = r.weightY[k];
  983.           int dy = (int)((wt * ((double)pixels_diff)) / weight);
  984.           r.minHeight[k] += dy;
  985.           pixels_diff -= dy;
  986.           weight -= wt;
  987.         }
  988.         /* Any leftovers go into the bottom cell */
  989.         r.minHeight[py-1] += pixels_diff;
  990.       }
  991.     }
  992.     else if (constraints.tempHeight > i &&
  993.          constraints.tempHeight < nextSize)
  994.       nextSize = constraints.tempHeight;
  995.       }
  996.     }
  997.  
  998.     return r;
  999.    }
  1000.   }
  1001.   
  1002.   /*
  1003.    * Adjusts the x, y, width, and height fields to the correct
  1004.    * values depending on the constraint geometry and pads.
  1005.    */
  1006.   protected void AdjustForGravity(GridBagConstraints constraints,
  1007.                   Rectangle r) {
  1008.     int diffx, diffy;
  1009.  
  1010.     r.x += constraints.insets.left;
  1011.     r.width -= (constraints.insets.left + constraints.insets.right);
  1012.     r.y += constraints.insets.top;
  1013.     r.height -= (constraints.insets.top + constraints.insets.bottom);
  1014.     
  1015.     diffx = 0;
  1016.     if ((constraints.fill != GridBagConstraints.HORIZONTAL &&
  1017.      constraints.fill != GridBagConstraints.BOTH)
  1018.     && (r.width > (constraints.minWidth + constraints.ipadx))) {
  1019.       diffx = r.width - (constraints.minWidth + constraints.ipadx);
  1020.       r.width = constraints.minWidth + constraints.ipadx;
  1021.     }
  1022.     
  1023.     diffy = 0;
  1024.     if ((constraints.fill != GridBagConstraints.VERTICAL &&
  1025.      constraints.fill != GridBagConstraints.BOTH)
  1026.     && (r.height > (constraints.minHeight + constraints.ipady))) {
  1027.       diffy = r.height - (constraints.minHeight + constraints.ipady);
  1028.       r.height = constraints.minHeight + constraints.ipady;
  1029.     }
  1030.     
  1031.     switch (constraints.anchor) {
  1032.     case GridBagConstraints.CENTER:
  1033.       r.x += diffx/2;
  1034.       r.y += diffy/2;
  1035.       break;
  1036.     case GridBagConstraints.NORTH:
  1037.       r.x += diffx/2;
  1038.       break;
  1039.     case GridBagConstraints.NORTHEAST:
  1040.       r.x += diffx;
  1041.       break;
  1042.     case GridBagConstraints.EAST:
  1043.       r.x += diffx;
  1044.       r.y += diffy/2;
  1045.       break;
  1046.     case GridBagConstraints.SOUTHEAST:
  1047.       r.x += diffx;
  1048.       r.y += diffy;
  1049.       break;
  1050.     case GridBagConstraints.SOUTH:
  1051.       r.x += diffx/2;
  1052.       r.y += diffy;
  1053.       break;
  1054.     case GridBagConstraints.SOUTHWEST:
  1055.       r.y += diffy;
  1056.       break;
  1057.     case GridBagConstraints.WEST:
  1058.       r.y += diffy/2;
  1059.       break;
  1060.     case GridBagConstraints.NORTHWEST:
  1061.       break;
  1062.     default:
  1063.       throw new IllegalArgumentException("illegal anchor value");
  1064.     }
  1065.   }
  1066.  
  1067.   /*
  1068.    * Figure out the minimum size of the
  1069.    * master based on the information from GetLayoutInfo()
  1070.    */
  1071.   protected Dimension GetMinSize(Container parent, GridBagLayoutInfo info) {
  1072.     Dimension d = new Dimension();
  1073.     int i, t;
  1074.     Insets insets = parent.getInsets();
  1075.  
  1076.     t = 0;
  1077.     for(i = 0; i < info.width; i++)
  1078.       t += info.minWidth[i];
  1079.     d.width = t + insets.left + insets.right;
  1080.  
  1081.     t = 0;
  1082.     for(i = 0; i < info.height; i++)
  1083.       t += info.minHeight[i];
  1084.     d.height = t + insets.top + insets.bottom;
  1085.  
  1086.     return d;
  1087.   }
  1088.  
  1089.   /*
  1090.    * Lay out the grid
  1091.    */
  1092.   protected void ArrangeGrid(Container parent) {
  1093.     Component comp;
  1094.     int compindex;
  1095.     GridBagConstraints constraints;
  1096.     Insets insets = parent.getInsets();
  1097.     Component components[] = parent.getComponents();
  1098.     Dimension d;
  1099.     Rectangle r = new Rectangle();
  1100.     int i, diffw, diffh;
  1101.     double weight;
  1102.     GridBagLayoutInfo info;
  1103.     
  1104.     /*
  1105.      * If the parent has no slaves anymore, then don't do anything
  1106.      * at all:  just leave the parent's size as-is.
  1107.      */
  1108.     if (components.length == 0 &&
  1109.     (columnWidths == null || columnWidths.length == 0) &&
  1110.     (rowHeights == null || rowHeights.length == 0)) {
  1111.       return;
  1112.     }
  1113.     
  1114.     /*
  1115.      * Pass #1: scan all the slaves to figure out the total amount
  1116.      * of space needed.
  1117.      */
  1118.     
  1119.     info = GetLayoutInfo(parent, PREFERREDSIZE);
  1120.     d = GetMinSize(parent, info);
  1121.  
  1122.     if (parent.width < d.width || parent.height < d.height) {
  1123.       info = GetLayoutInfo(parent, MINSIZE);
  1124.       d = GetMinSize(parent, info);
  1125.     }
  1126.  
  1127.     layoutInfo = info;
  1128.     r.width = d.width;
  1129.     r.height = d.height;
  1130.  
  1131.     /*
  1132.      * DEBUG
  1133.      *
  1134.      * DumpLayoutInfo(info);
  1135.      * for (compindex = 0 ; compindex < components.length ; compindex++) {
  1136.      * comp = components[compindex];
  1137.      * if (!comp.isVisible())
  1138.      *    continue;
  1139.      * constraints = lookupConstraints(comp);
  1140.      * DumpConstraints(constraints);
  1141.      * }
  1142.      * System.out.println("minSize " + r.width + " " + r.height);
  1143.      */
  1144.     
  1145.     /*
  1146.      * If the current dimensions of the window don't match the desired
  1147.      * dimensions, then adjust the minWidth and minHeight arrays
  1148.      * according to the weights.
  1149.      */
  1150.     
  1151.     diffw = parent.width - r.width;
  1152.     if (diffw != 0) {
  1153.       weight = 0.0;
  1154.       for (i = 0; i < info.width; i++)
  1155.     weight += info.weightX[i];
  1156.       if (weight > 0.0) {
  1157.     for (i = 0; i < info.width; i++) {
  1158.       int dx = (int)(( ((double)diffw) * info.weightX[i]) / weight);
  1159.       info.minWidth[i] += dx;
  1160.       r.width += dx;
  1161.       if (info.minWidth[i] < 0) {
  1162.         r.width -= info.minWidth[i];
  1163.         info.minWidth[i] = 0;
  1164.       }
  1165.     }
  1166.       }
  1167.       diffw = parent.width - r.width;
  1168.     }
  1169.     else {
  1170.       diffw = 0;
  1171.     }
  1172.     
  1173.     diffh = parent.height - r.height;
  1174.     if (diffh != 0) {
  1175.       weight = 0.0;
  1176.       for (i = 0; i < info.height; i++)
  1177.     weight += info.weightY[i];
  1178.       if (weight > 0.0) {
  1179.     for (i = 0; i < info.height; i++) {
  1180.       int dy = (int)(( ((double)diffh) * info.weightY[i]) / weight);
  1181.       info.minHeight[i] += dy;
  1182.       r.height += dy;
  1183.       if (info.minHeight[i] < 0) {
  1184.         r.height -= info.minHeight[i];
  1185.         info.minHeight[i] = 0;
  1186.       }
  1187.     }
  1188.       }
  1189.       diffh = parent.height - r.height;
  1190.     }
  1191.     else {
  1192.       diffh = 0;
  1193.     }
  1194.  
  1195.     /*
  1196.      * DEBUG
  1197.      *
  1198.      * System.out.println("Re-adjusted:");
  1199.      * DumpLayoutInfo(info);
  1200.      */
  1201.     
  1202.     /*
  1203.      * Now do the actual layout of the slaves using the layout information
  1204.      * that has been collected.
  1205.      */
  1206.     
  1207.     info.startx = diffw/2 + insets.left;
  1208.     info.starty = diffh/2 + insets.top;
  1209.  
  1210.     for (compindex = 0 ; compindex < components.length ; compindex++) {
  1211.       comp = components[compindex];
  1212.       if (!comp.isVisible())
  1213.     continue;
  1214.       constraints = lookupConstraints(comp);
  1215.  
  1216.       r.x = info.startx;
  1217.       for(i = 0; i < constraints.tempX; i++)
  1218.     r.x += info.minWidth[i];
  1219.       
  1220.       r.y = info.starty;
  1221.       for(i = 0; i < constraints.tempY; i++)
  1222.     r.y += info.minHeight[i];
  1223.       
  1224.       r.width = 0;
  1225.       for(i = constraints.tempX;
  1226.       i < (constraints.tempX + constraints.tempWidth);
  1227.       i++) {
  1228.     r.width += info.minWidth[i];
  1229.       }
  1230.       
  1231.       r.height = 0;
  1232.       for(i = constraints.tempY;
  1233.       i < (constraints.tempY + constraints.tempHeight);
  1234.       i++) {
  1235.     r.height += info.minHeight[i];
  1236.       }
  1237.       
  1238.       AdjustForGravity(constraints, r);
  1239.       
  1240.       /*
  1241.        * If the window is too small to be interesting then
  1242.        * unmap it.  Otherwise configure it and then make sure
  1243.        * it's mapped.
  1244.        */
  1245.       
  1246.       if ((r.width <= 0) || (r.height <= 0)) {
  1247.     comp.setBounds(0, 0, 0, 0);
  1248.       }
  1249.       else {
  1250.     if (comp.x != r.x || comp.y != r.y ||
  1251.         comp.width != r.width || comp.height != r.height) {
  1252.       comp.setBounds(r.x, r.y, r.width, r.height);
  1253.     }
  1254.       }
  1255.     }
  1256.   }
  1257. }
  1258.